home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 3484 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  74 lines

  1. Path: ansible.bbt.com!newsadmin
  2. From: mab@pathos.bbt.com (Michael A. Bridgers)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: References troubles
  5. Date: 20 Feb 1996 15:52:27 GMT
  6. Organization: BroadBand Technologies Inc.
  7. Message-ID: <MAB.96Feb20105227@pathos.bbt.com>
  8. References: <1266.6624T117T1455@himolde.no>
  9. NNTP-Posting-Host: 192.154.90.1
  10. In-reply-to: Espen.Berntsen@himolde.no's message of 20 Feb 1996 14:09:59 GMT
  11.  
  12. In article <1266.6624T117T1455@himolde.no> Espen.Berntsen@himolde.no (Nameless) writes:
  13. > Ok, I have aslight problem with references. The problem is that I have to pass a
  14. > few pointers to a subroutine, where things are done to them, and then they are
  15. > passed back. Now, what I hoped would work was something like this
  16. > =========== Cut cut cut ===============================
  17. > #include <stdio.h>
  18. > #include <proto/dos.h>
  19. > #include <proto/exec.h>
  20. > #include <exec/memory.h>
  21. > void Tester(void &Testering)
  22. > {
  23. >     Testering = <some value>;
  24. > }
  25. > void main(void)
  26. > {
  27. >     void *Test;
  28. >     Tester(Test);
  29. >       <use the 'Test' value>
  30. >       ...
  31. > }
  32. > ====================== cut cut cut =======================
  33. > Now, this of course don't work. But Ill be damned if I know how to get it to
  34. > work. By reading the test program you should hopefully be able to understand
  35. > what I mean. PLEASE can someone help..
  36. > And no, I can't just return the value, 'cause there will be many such values.
  37. > And I don't want to return a structure.
  38.  
  39. If you are trying to program in C, the problem is that C dosen't have references.
  40. You need to pass a 'void**' (void-star-star).
  41.  
  42. If you are trying to program in C++, you are not allowed to pass a 'void&' (a
  43. void reference). You *can* however, pass a 'void *&' (a void-star reference). This
  44. is a reference to a 'void*'.  Your code would look like this:
  45.  
  46. void Tester(void *&Testering)
  47. {
  48.         Testering = <some value>;
  49. }
  50.  
  51. void main(void)
  52. {
  53.     void *Test;
  54.  
  55.     Tester(Test);
  56.         <use the 'Test' value>
  57.         ...
  58. }
  59. -- 
  60. ============================================================
  61. Michael Bridgers                +     Phone : (919) 405-4627
  62. BroadBand Technologies, Inc.   _|_
  63. Research Triangle Park, NC    (   )   email : mab@bbt.com
  64.                                ) (
  65.                               (_ _)
  66.                                 |
  67. ============================================================
  68.